//
//  DXBaseManagerObject.m
//  iDxyer
//
//  Created by sun black on 11-11-18.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "WCBaseManagerObject.h"

@implementation WCBaseManagerObject



@synthesize richTitle;
@synthesize richBody;

+(NSString *)entityName{
    return NSStringFromClass([self class]);
}

+(id)entityFromCoreDataContext{
    return [NSEntityDescription insertNewObjectForEntityForName:[self entityName] inManagedObjectContext:[WCCoreDataContext sharedInstance].managedObjectContext];
}
+(id)entityWithId:(id)aId{
    NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:[self entityName]];
    request.predicate = [NSPredicate predicateWithFormat:@"self.id=%@",aId];
    NSError *error = nil;
    NSArray *entities = [[WCCoreDataContext sharedInstance].managedObjectContext executeFetchRequest:request error:&error];
    if (error) {
        NSLog(@"ERROR:%@-----%@",error.domain,error.description);
        return nil;
    }
    return entities.count>0?[entities objectAtIndex:0]:nil;
}

/*-(DXTableItem *)transformToTableItem{
    NSLog(@"do nothing,subclass should overwite it");
    return nil;
}*/

-(void)didTurnIntoFault{
    [super didTurnIntoFault];
}

+ (NSMutableArray *)transformToTableItemsFromEntityArray:(NSArray *)entityArray {
    NSMutableArray *tableItems = [NSMutableArray array];
    return tableItems;
}

-(void)refreshWithMergeChanges:(BOOL)merge{
    [[WCCoreDataContext sharedInstance].managedObjectContext refreshObject:self mergeChanges:merge];
}

-(void)insertIntoCoreDataContext{
    [[WCCoreDataContext sharedInstance].managedObjectContext insertObject:self];
}
-(void)deleteFromCoreDataContext{
    [[WCCoreDataContext sharedInstance].managedObjectContext deleteObject:self];
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
    NSLog(@"entity:%@ don't response key:%@",[[self class] entityName],key);
}

@end
